<template>
	<view class="container page">
		<view class="couponList" v-for="(item,index) in couponList.coupon_list" v-bind:key="index">
			<image :src="url+'/static/imgs/coupon-bg.png'"></image>
			<view class="couponlist_content row">
				<view class="couponlst_price">
					<text>￥{{item.coupon_info.money}}</text>
					<text>满{{item.coupon_info.need_money}}元可用</text>
				</view>
				<view class="couponlst_menu">
					<text class="couponlsttitle">{{item.coupon_info.name}}</text>
					<text class="couponlsttime">有效期：{{item.start_time}}~{{item.end_time}}</text>
					<view class="couponlstbutton" @click="toUse" :data-index="index">立即使用</view>
				</view>
			</view>
		</view>
		<view class="col empty-view" v-if="couponList.coupon_list.length==0">
			<image :src="url+'/static/imgs/list-empty-common.png'"></image>
			<text class="empty-text">我的优惠券竟然是空的</text>
			<view class="empty-button" @click="toRedPacket">快去领券</view>
		</view>
	</view>
</template>

<script>
	var app = getApp();
	import http from "../../../common/js/request.js";
	export default {
		data() {
			return {
				url: app.globalData.baseImgUrl,
				store_id: app.globalData.storeId,
				couponList: [], //优惠券信息
				choose: false
			}
		},
		onLoad() {
			var that = this;
			that.getCouponList();
		},
		
		methods: {
			//获取优惠券信息
			getCouponList() {
				var that = this;
				if (app.globalData.couponList) {
					that.couponList = {};
					that.couponList.coupon_list = app.globalData.couponList;
					that.choose = true;
				} else {
					http.post('/api/v1/store/get_member_store_coupon', {
						store_id: that.store_id
					}, res => {
						that.couponList = res.datas;
					});
				}
			},
			//跳转至点餐（分类页面）/使用
			toUse(e) {
				var that = this;
				if (that.choose) {
					var index = e.currentTarget.dataset.index;
					app.globalData.chooseCouponInfo = that.couponList.coupon_list[index];
					console.log('app.globalData.chooseCouponInfo', app.globalData.chooseCouponInfo);
					uni.navigateBack();
				} else {
					uni.switchTab({
						url: '/pages/store/category/category'
					});
				}
			},
			//跳转到抢红包页
			toRedPacket(){
				uni.navigateTo({
					url: '/pages/store/redPacket/redPacket'
				});
			}
		}
	}
</script>

<style>
	/* 缺省样式 */
	.empty-view {
		margin-top: 183rpx;
		align-items: center;
		justify-content: center;
	}

	.empty-view image {
		width: 195rpx;
		height: 269rpx;
	}

	.empty-view .empty-text {
		margin-top: 80rpx;
		color: #333333;
		font-size: 36rpx;
	}

	.empty-view .empty-button {
		margin-top: 120rpx;
		width: 512rpx;
		height: 100rpx;
		background: rgba(255, 157, 17, 1);
		border-radius: 10rpx;
		font-size: 34rpx;
		color: #fff;
		display: flex;
		align-items: center;
		justify-content: center;
	}

	/* 缺省样式 */
	.page {
		width: 100%;
		height: 100%;
		background: rgba(247, 247, 247, 1);
		position: absolute;
	}

	.couponList {
		width: 690rpx;
		height: 201rpx;
		margin: 20rpx auto 0;
		position: relative;
	}

	.couponList image {
		width: 100%;
		height: 100%;
	}

	.couponlist_content {
		width: 690rpx;
		height: 201rpx;
		position: absolute;
		top: 0;
		left: 50%;
		margin-left: -345rpx;
	}

	.couponlst_price {
		width: 220rpx;
	}

	.couponlst_price text {
		display: block;
		text-align: center;
		font-size: 28rpx;
		color: #fff;
		line-height: 70rpx;
	}

	.couponlst_price text:nth-child(1) {
		font-size: 50rpx;
		font-weight: bold;
		margin-top: 30rpx;
	}

	.couponlst_menu {
		width: 450rpx;
		margin-left: 20rpx;
		line-height: 50rpx;
	}

	.couponlst_menu text {
		display: block;
	}

	.couponlsttitle {
		font-size: 32rpx;
		margin-top: 10rpx;
	}

	.couponlsttime {
		font-size: 28rpx;
		color: #999999;
	}

	.couponlstbutton {
		width: 404rpx;
		height: 53rpx;
		line-height: 53rpx;
		background: rgba(255, 157, 17, 1);
		border-radius: 10rpx;
		color: #fff;
		text-align: center;
		font-size: 28rpx;
		margin-top: 20rpx;
	}
</style>
